import React, { Component } from 'react'
import { connect } from 'dva';
import FormList from '../components/FormItem';

interface IProps {
  dispatch: Function,
  data: {
    id: number
  },
  match: {
    params: {
      id: number
    }
  },
  details: object
}

const Keys = [
  'id',
  'loginName',
  'realName',
  'photo',
  'mobile',
  'position',
  'email',
  'jobNumber',
  'remark',
]

@connect(({ person }) => ({
  data: person.editDetails
}))
class Update extends Component<IProps> {

  componentDidMount() {
    const { dispatch, match } = this.props;
    const { params } = match;

    dispatch({
      type: 'person/queryEditInfoById',
      payload: {
        id: params.id,
        keys: Keys
      }
    })
  }

  render() {
    return (
      <section className="edit">
        <FormList data={this.props.data} key={Date.now()}/>
      </section>
    );
  }
}

export default Update;